package cn.edu.scau.sec.caixiaoqing.abstractFactory;

import cn.edu.scau.sec.caixiaoqing.abstractFactory.abstractClass.ConsumerElectronics;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public abstract class AbstractFactory {

    public static AbstractFactory getAbstractFactory(String brand) throws Exception {
        Class<?> Factory = Class.forName(brand);
        Constructor<?> constructor = Factory.getConstructor();
        AbstractFactory abstractFactory = (AbstractFactory) constructor.newInstance();
        return abstractFactory;
    }

    public ConsumerElectronics getConsumerElectronics(String type) throws Exception {
        Class<? extends AbstractFactory> aClass = this.getClass();
        Method method = aClass.getMethod(type);
        return (ConsumerElectronics) method.invoke(this);
    }

    public abstract ConsumerElectronics getPad();
    public abstract ConsumerElectronics getWatch();
    public abstract ConsumerElectronics getPhone();
}
